#include "feMaterial.h"
#include "feMeshFunction.h"

feMaterial::feMaterial(double iDivGradCoeff, double iWeightCoeff, double iDudtCoeff, 
								   feMeshFunction *iRightFunc, double iScaleF, double iScaleP, double iScaleT)
{
	DivGradCoeff = iDivGradCoeff;
	WeightCoeff = iWeightCoeff;
	DudtCoeff = iDudtCoeff;
	RightFunc = iRightFunc;
	ScaleF = iScaleF;
	ScaleP = iScaleP;
	ScaleT = iScaleT;
}


//----------------------------------------------------------------------------------------------------------------------------------------------
void feMaterial::SetRight(feMeshFunction *iNewF, double iScaleF, double iScaleP, double iScaleT)
{
	RightFunc = iNewF;
	ScaleF = iScaleF;
	ScaleP = iScaleP;
	ScaleT = iScaleT;
}


//----------------------------------------------------------------------------------------------------------------------------------------------
void feMaterial::Copy(feMaterial *iMaterial)
{
	DivGradCoeff = iMaterial->DivGradCoeff;
	WeightCoeff = iMaterial->WeightCoeff;
	DudtCoeff = iMaterial->DudtCoeff;
	RightFunc = iMaterial->RightFunc;
	ScaleF = iMaterial->ScaleF;
	ScaleP = iMaterial->ScaleP;
	ScaleT = iMaterial->ScaleT;
}


//----------------------------------------------------------------------------------------------------------------------------------------------
double feMaterial::GetF(fePoint *iPoint, int iLayer, int *iIndex) 
{ 
	if( ((feMeshFunction *)RightFunc) == NULL || ScaleF == 0) return ScaleF;
	
	//cache
	if(LastT == iLayer && LastP.X == iPoint->X)
		return LastF;

	LastT = iLayer;
	LastP = *iPoint;
	fePoint p = iPoint->X * ScaleP;
	LastF = ScaleF*RightFunc->GetU(&p, iLayer, iIndex); 
	return LastF;
}